package chap_10.v2;

import org.junit.jupiter.api.Test;

import java.util.Optional;

public class Run {


    @Test
    public void testV2() {
        Optional<Person> person = Optional.of(new Person());
        /*Optional<String> s = person
                .map(Person::getCar)
                .map(Car::getInsurance)
                .map(Insurance::getName);*/

        String s = person
                .flatMap(Person::getCar)
                .flatMap(Car::getInsurance)
                .map(Insurance::getName).orElse("unknown");
        System.out.println(s);
    }
}
